﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics.Tracing;
using System.Diagnostics;

namespace TestThread
    {
    class TabAddition
        {
        /*---------------------------------------------*\
        |*               Methodes public               *|
        \*---------------------------------------------*/
        /*---------------------*\
        |*        static       *|
        \*---------------------*/
        static public double[] additionner(ref double[] tab1, ref double[] tab2)
            {
            Debug.Assert(tab1.Length == tab2.Length);
            double[] tabResult = new double[tab1.Length];
            int nbProcess = System.Environment.ProcessorCount;
            Thread[] tabThread = new Thread[nbProcess];

            for (int i = 0; i < tabThread.Length; i++)
                {
                tabThread[i] = new Thread(new ThreadStart(new ThreadAdd(tab1, tab2, tabResult, nbProcess, i).add));
                tabThread[i].Start();
                }

            foreach (Thread thread in tabThread)
                {
                thread.Join();
                }
            
            return tabResult;
            }
        }
    }
